package com.woniu.his.controller;

import com.woniu.his.entity.DocterInfo;
import com.woniu.his.entity.Doctor;
import com.woniu.his.entity.RegistrationInfo;
import com.woniu.his.entity.SectionInfo;
import com.woniu.his.service.IRegistrationInfoService;
import com.woniu.his.service.ISectionInfoService;
import com.woniu.his.service.ISectionTypeService;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName GuaHaoController
 * @Description 挂号操作
 * @Author li
 * @Date 2019/11/25 0025 18:49
 * @Version V1.0
 **/
@Controller
public class GuaHaoController {
    @Autowired
    private ISectionTypeService iSectionTypeService;

    @Autowired
    private ISectionInfoService iSectionInfoService;

    @Autowired
    private IRegistrationInfoService iRegistrationInfoService;
    /**
     *@描述
     *@参数  根据传进来的一级科室查找对应的二级科室
     *@返回值  
     *@创建人  li
     *@创建时间  2019/11/25 0025
     *@修改人和其它信息
     */
    @RequestMapping("findSectionInfo")
    @ResponseBody
    @RequiresRoles("挂号部")
    public List<SectionInfo> findSectionInfoBySectionType(String sectionType){

        if ("请选择".equals(sectionType)){
            return null;
        }
        return iSectionTypeService.findSectionInfo(sectionType);
    }

    /**
     *@描述
     *@参数  根据传进来的二级科室的名称查找所有对应的医生
     *@返回值  
     *@创建人  li
     *@创建时间  2019/11/25 0025
     *@修改人和其它信息
     */
    @RequestMapping("getDoctor")
    @ResponseBody
    @RequiresRoles("挂号部")
    public List<Doctor> findDoctorBySectionInfo(Integer sectionId){
        System.out.println("拿到的id为===>"+sectionId);
        List<DocterInfo> docters = iSectionInfoService.findDoctorByTwoSectionName(sectionId);

        List<Doctor> newDocters = new ArrayList<>();
//        遍历集合,将docters的信息封装
        for (DocterInfo doc:docters) {
            Doctor doctor = new Doctor();
            doctor.setDoctorId(doc.getDocterId());
            doctor.setDoctorName(doc.getDocterName());
            doctor.setDoctorSectionId(doc.getSectionId());
            newDocters.add(doctor);
        }
        System.out.println("封装后的医生====>"+newDocters);
        return newDocters;
    }

    /**
     *@描述
     *@参数  患者信息录入
     *@返回值  
     *@创建人  li
     *@创建时间  2019/11/25 0025
     *@修改人和其它信息
     */
    @RequiresRoles("挂号部")
    @RequestMapping("addRegistrationInfo")
    public String addRegistrationInfo(RegistrationInfo re){
        System.out.println("表单提交请求进来了");
        System.out.println(re.getHandleId());
//        System.out.println(re.getRegistrationName());
//        System.out.println(re.getRegistrationTime());
//        System.out.println(re.getRegistrationSectionId());
//        System.out.println(re.getRegistrationDocterId());
        iRegistrationInfoService.addRegistration(re);
        return "guahao";
    }

    //这是进入挂号页面的请求
    @GetMapping("guahao")
    @RequiresRoles("挂号部")
    public String guahao() {
        return "guahao";
    }
}
